home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 4
/
Apprentice-Release4.iso
/
Source Code
/
Libraries
/
PNL Libraries
/
MyRestartMac.p
< prev
next >
Wrap
Text File
|
1995-03-19
|
2KB
|
84 lines
unit MyRestartMac;
interface
procedure RestartMac;
implementation
uses
Processes, GestaltEqu, AppleEvents;
const
finder_type = 'FNDR';
finder_creator = 'MACS';
finder_suite = 'FNDR';
finder_restart = 'rest';
finder_shutdown = 'shut';
function GetFinderPSN (var process: ProcessSerialNumber): boolean;
var
info: ProcessInfoRec;
s: str63;
fs: FSSpec;
oe: OSErr;
gv: longInt;
begin
GetFinderPSN := false;
if (Gestalt(gestaltOSAttr, gv) = noErr) & (BTST(gv, gestaltLaunchControl)) then begin
process.highLongOfPSN := 0;
process.lowLongOfPSN := kNoProcess;
info.processInfoLength := sizeof(ProcessInfoRec);
info.processName := @s;
info.processAppSpec := @fs;
while GetNextProcess(process) = noErr do begin
if GetProcessInformation(process, info) = noErr then
if (info.processType = longInt(finder_type)) and (info.processSignature = finder_creator) then begin
GetFinderPSN := true;
leave;
end;
end;
end;
end;
procedure AECreate (var desc: AEDesc);
begin
desc.descriptorType := typeNull;
desc.dataHandle := nil;
end;
procedure AEDestroy (var desc: AEDesc);
var
junk: OSErr;
begin
junk := AEDisposeDesc(desc);
AECreate(desc);
end;
procedure SendSimpleEvent (psn: ProcessSerialNumber; class_id, event_id: AEEventID);
var
event, reply: AppleEvent;
err, junk: OSErr;
target: AEDesc;
begin
AECreate(reply);
err := AECreateDesc(typeProcessSerialNumber, @psn, SizeOf(psn), target);
err := AECreateAppleEvent(class_id, event_id, target, kAutoGenerateReturnID, kAnyTransactionID, event);
AEDestroy(target);
if err = noErr then begin
junk := AESend(event, reply, kAENoReply + kAEAlwaysInteract, kAENormalPriority, kAEDefaultTimeOut, nil, nil);
end;
AEDestroy(event);
AEDestroy(reply);
end;
procedure RestartMac;
var
process: ProcessSerialNumber;
begin
if GetFinderPSN(process) then begin
SendSimpleEvent(process, finder_suite, finder_restart);
end;
end;
end.